package de.Ox539.nagroid;

import junit.framework.TestCase;

public class TimeRangeTest extends TestCase {

	public void testSerialize() {
		TimeRange range = new TimeRange();
		range.setStartHour(8);
		range.setStartMinute(10);
		range.setEndHour(15);
		range.setEndMinute(30);
		assertEquals("8:10-15:30", range.serialize());
		range.setEndHour(3);
		assertEquals("8:10-3:30", range.serialize());
	}

	public void testDeserialize() {
		TimeRange range = TimeRange.deserialize("1:0-3:0");
		assertEquals(1, range.getStartHour());
		assertEquals(0, range.getStartMinute());
		assertEquals(3, range.getEndHour());
		assertEquals(0, range.getEndMinute());
		range = TimeRange.deserialize("01:02-03:07");
		assertEquals(1, range.getStartHour());
		assertEquals(2, range.getStartMinute());
		assertEquals(3, range.getEndHour());
		assertEquals(7, range.getEndMinute());
		range = TimeRange.deserialize("03:02-01:07");
		assertEquals(3, range.getStartHour());
		assertEquals(2, range.getStartMinute());
		assertEquals(1, range.getEndHour());
		assertEquals(7, range.getEndMinute());
	}

	public void testInRangeNoWrap() {
		TimeRange range = TimeRange.deserialize("08:00-23:00");
		assertTrue(range.inRange(8, 0));
		assertTrue(range.inRange(9, 0));
		assertTrue(range.inRange(14, 0));
		assertFalse(range.inRange(23, 0));
	}
	
	public void testInRangeWrap() {
		TimeRange range = TimeRange.deserialize("08:00-03:00");
		assertTrue(range.inRange(8, 0));
		assertTrue(range.inRange(8, 1));
		assertTrue(range.inRange(12, 0));
		assertTrue(range.inRange(14, 30));
		assertTrue(range.inRange(24, 0));
		assertTrue(range.inRange(0, 0));
		assertTrue(range.inRange(1, 0));
		assertTrue(range.inRange(2, 59));
		assertFalse(range.inRange(3, 0));
		assertFalse(range.inRange(5, 30));
		assertFalse(range.inRange(7, 59));
	}
}
